package com.example.mbl.controller;

import com.example.mbl.entity.User;
import com.example.mbl.interceptor.AppToken;
import com.example.mbl.result.PageResult;
import com.example.mbl.result.WebRestResult;
import com.example.mbl.result.business.UserPageResult;
import com.example.mbl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("User")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("login")
    public WebRestResult login(String username,String password){
        WebRestResult result = userService.loginUser(username,password);
        return result;
    }

    @GetMapping("getUserList")
    public PageResult<UserPageResult> getUserList(int page,int pagesize){
        PageResult<UserPageResult> result = userService.getUserList(page,pagesize);
        return result;
    }

    @AppToken
    @PostMapping("addUser")
    public WebRestResult addUser(@RequestBody User user){
        WebRestResult result = userService.addUser(user);
        return result;
    }

    @AppToken
    @PostMapping("updateUser")
    public WebRestResult updateUser(@RequestBody User user){
        WebRestResult result = userService.updateUser(user);
        return result;
    }

    @AppToken
    @PostMapping("deleteUser")
    public WebRestResult deleteUser(@RequestBody User user){
        WebRestResult result = userService.deleteUser(user);
        return result;
    }
}
